package com.flightcloud.ssm.user.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.view.RedirectView;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.flightcloud.ssm.user.entity.User;
import com.flightcloud.ssm.user.service.IUserService;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author chenjj
 * @since 2017-03-12
 */
@Controller
@RequestMapping("user")
public class UserController {

	@Autowired
	private IUserService userService;

	@ModelAttribute
	@RequestMapping("userList")
	public List<User> userList(int current,int size,User user) {
		EntityWrapper<User> entityWrapper = new EntityWrapper<User>(user);
		Page<User> page = new Page<>(current,size);
		userService.selectPage(page, entityWrapper);
		return page.getRecords();
	}
	
	@RequestMapping(value = "insert", method = RequestMethod.GET)
	public void insert() {
	}

	@RequestMapping(value = "insert", method = RequestMethod.POST)
	public RedirectView insert(User user) {
		RedirectView view = new RedirectView("/user/userList");
		boolean result = userService.insert(user);
		view.setContextRelative(true);
		return view;
	}
}
